package com.sean.common.mybatis.dialect;

/**
 * An SQL dialect for Oracle.
 * 
 * @author XinWang
 * 
 */
public class OracleDialect extends Dialect {

    @Override
    public String getLimitString(String sql, int offset, int limit) {

	sql = sql.trim();
	StringBuffer pagingSelect = new StringBuffer();
	pagingSelect.append("select * from ( select row_.*, rownum rownum_ from ( ");
	pagingSelect.append(sql);
	pagingSelect.append(" ) row_ ) where rownum_ > ").append(offset).append(" and rownum_ <= ").append(offset + limit);
	return pagingSelect.toString();
    }

    @Override
    public String getCountString(String originalSql) {
	return "select count(1) from ( " + originalSql + " ) t";
    }

}